import { request } from "@/http/axios"
import * as XLSX from "xlsx";
export function FileDownloadFiaName(fileName) {
  const url = `upload/downloadFile?fileName=${encodeURIComponent(fileName)}`;
  return request({
    url: url,
    method: 'get',
    responseType: 'blob',
  })
}

export function AuditsOpinion(opinionList){
  return request({
    url: '/audits/opinionList',
    method: "post",
    data: {
      opinionList: opinionList
    }
  })
}

export function getPageAccountList(data){
  return request({
    url: '/userprofile/list',
    method: "get",
    params: data
  })
}

export function batchAddAccount(data){
  return request({
    url: '/userprofile/batchAdd',
    method: "post",
    data: data
  })
}

export function updateAccount(data){
  return request({
    url: '/userprofile',
    method: "put",
    data: data
  })
}
export function deletesAccount(data){
  return request({
    url: '/userprofile/batchDelete?ids='+data,
    method: "delete"
  })
}


//项目进度新增
export function addProjectProgress(data){
  return request({
    url: '/progress',
    method: "post",
    data: data
  });
}

//项目过程新增
export function addProjectProgressReview(data){
  return request({
    url: '/progress/review',
    method: "post",
    data: data
  });
}

//项目进度列表
export function getProjectProgressList(data){
  return request({
    url: '/progress/list?projectId='+data,
    method: "get"
  });
}
//项目进度列表
export function getProjectProgressListIds(data){
  return request({
    url: '/progress/projectIds?projectIds='+data,
    method: "get"
  });
}

//项目审核
export function auditProjectAudit(data){
  return request({
    url: '/progress/audit',
    method: "post",
    data: data
  });
}
//导出数据表格
export function exportFileExcel(data,fileName) {
  let tableData = [
    ['序号', '用户名', '手机号', '性别', '邮箱', '创建者', '创建时间', '状态']//导出表头
  ] // 表格表头
  data.forEach((item, index) => {
    let rowData = []
    //导出内容的字段
    rowData = [
      index + 1,
      item.username,
      item.mobile,
      item.sex,
      item.email,
      item.creator,
      item.createDate,
      item.status
    ]
    tableData.push(rowData)
  })
  let workSheet = XLSX.utils.aoa_to_sheet(tableData);
  let bookNew = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(bookNew, workSheet, '作品名称') // 工作簿名称
  let name = fileName+'用户数据' + timeFormats() + '.xlsx'
  XLSX.writeFile(bookNew, name) // 保存的文件名
}
export function timeFormats() {
  let time = new Date();
  let year = time.getFullYear();
  let month = time.getMonth() + 1;
  let date = time.getDate();
  let hours = time.getHours();
  let minutes = time.getMinutes();
  let seconds = time.getSeconds();
  return year + '-' + addZero(month) + '-' + addZero(date) + ' ' + addZero(hours) + ':' + addZero(minutes) + ':' + addZero(seconds);
}
export function addZero(num) {
  return num < 10 ? '0' + num : num
}

// 查询用户认证列表
export function getCertificationList(data) {
  return request({
    url: '/authentication/list',
    method: "get",
    params: data
  });
}
//编辑用户认证
export function editCertification(data) {
  return request({
    url: '/authentication',
    method: "put",
    data: data
  });
}
// 项目资金申请
export function addProjectFunding(data) {
  return request({
    url: '/projectFunding',
    method: "post",
    data: data
  });
}
// 资金申请编辑
export function editProjectFunding(data) {
  return request({
    url: '/projectFunding',
    method: "put",
    data: data
  });
}


// 根据项目id查询项目资金申请详情
export function getProjectFundingDetailId(id) {
  return request({
    url: '/projectFunding/info?id=' + id,
    method: "get"
  });
}

//导出用户认证列表数据
export function exportCertificationList(data) {
  let tableData = [
    ['序号', '用户名', '工号','手机号','邮箱','认证类型', '认证状态','认证资料','创建时间']//导出表头
  ] // 表格表头
  data.forEach((item, index) => {
    let rowData = []
    //导出内容的字段
    rowData = [
      index + 1,
      item.username,
      item.workNumber,
      item.mobile,
      item.email,
      item.userType===0?'学生':item.userType===1?'教师':'管理员',
      item.status===0?'待认证': item.status===1?"通过": item.status===2?"未通过":'驳回',
      item.fileList,
      item.createDate,
    ]
    tableData.push(rowData)
  })
  let workSheet = XLSX.utils.aoa_to_sheet(tableData);
  let bookNew = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(bookNew, workSheet, '作品名称') // 工作簿名称
  let name = '用户认证数据' + timeFormats() + '.xlsx'
  XLSX.writeFile(bookNew, name) // 保存的文件名
}
// 向用户发送请求，是否同意重置密码
export function sendResetPasswordEmail(data,adminId) {
  const userResetUrl = 'http://localhost:3333/#/userReset'
    return request({
        url: '/userprofile/resetPasswordEmail',
        method: "post",
        data: {
            id: data.id,
            sex: adminId,
            email: data.email,
            creator: userResetUrl,
            username: data.realName
        }
    });
}
export function checkResetPasswordById(id){
  return request({
    url: '/userprofile/checkResetPassword?userId='+id,
    method: "get"
  });
}

// 用户认证规则数据
export function getCertificationRule(type) {
  return request({
    url: '/authentication/rule?userType='+type,
    method: "get"
    });
}
// 编辑用户认证规则数据
export function editCertificationRule(data) {
  return request({
    url: '/authentication/rule',
    method: "put",
    data: data
  });
}
// 智能审核
export function smartAudit(data) {
  return request({
    url: '/authentication/smartAudit',
    method: "post",
    data: data
  });
}


// 用户认证数据

// 查询用户认证数据列表
export function getCertificationInformationList(data) {
  return request({
    url: '/certification',
    method: "get",
    params: data
  });
}

// 新增用户认证数据
export function addCertificationInformation(data) {
  return request({
    url: '/certification',
    method: "post",
    data: data
  });
}
// 编辑用户认证数据
export function editCertificationInformation(data) {
  return request({
    url: '/certification',
    method: "put",
    data: data
  });
}

// 删除用户认证数据
export function deleteCertificationInformation(ids) {
  return request({
    url: '/certification?ids=' + ids,
    method: "delete"
  });
}

// 导出用户认证数据
export function exportCertificationInformation(data) {
  let tableData = [
    ['序号', '用户姓名', '认证号','手机号','邮箱','用户类型','创建时间','修改时间']//导出表头
  ] // 表格表头
  data.forEach((item, index) => {
    let rowData = []
    //导出内容的字段
    rowData = [
      index + 1,
      item.username,
      item.workNumber,
      item.mobile,
      item.email,
      item.userType===0?'学生':item.userType===1?'教师':'管理员',
      item.createDate,
      item.updateDate,
    ]
    tableData.push(rowData)
  })
  let workSheet = XLSX.utils.aoa_to_sheet(tableData);
  let bookNew = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(bookNew, workSheet, '作品名称') // 工作簿名称
  let name = '用户认证数据' + timeFormats() + '.xlsx'
  XLSX.writeFile(bookNew, name) // 保存的文件名
}








